{extend name='common/common' /}

{block name='style'}
<style media="screen">
.edui-default{
	line-height: 0;
}
</style>
{/block}
{block name="component"}
<div id="mapToolBox">
	<el-dialog title="描点（右键添加点，可以拖动的哦）" :visible.sync="showMap" fullscreen>
		<iframe id="aMap" src="{:url('Gis/map_addpoint_tool')}" width="100%" height="600" frameborder="0"></iframe>
		<div slot="footer" class="dialog-footer">
			<el-button @click="showMap = false">取消</el-button>
			<el-button type="success" @click="surePoint">确定</el-button>
		</div>
	</el-dialog>
</div>
<script type="text/javascript">
var map = new Vue({
	el:"#mapToolBox",
	data:{
		showMap:false,
	},
	methods:{
		surePoint() {
			if(aMap.contentWindow.mapBox.isAdd){
				var i = this.index;
				var position = aMap.contentWindow.mapBox.getPosition();
				main.form.lnglat= position.lng+","+position.lat;
				this.showMap = false;
				var address = aMap.contentWindow.mapBox.getLocation(position.lng,position.lat,this.getAddress);
			}else{
				this.showMap = false;
			}
		},
		getAddress(res) {
			main.form.address = res.address;
		}
	}
})
</script>
{/block}

{block name="content"}
<el-row>
<el-col :md="18">
<el-card class="box-card">
	<div slot="header">政府账号信息注册</div>
	<div>
		<el-form
			label-width="130px" :model="form" inline="true"
			:rules="rules" ref="form" class="curForm">
			<el-form-item label="县登录编码" prop="user_name">
				<el-input v-model="form.user_name" disabled clearable></el-input>
			</el-form-item>
			<el-form-item label="所属地区" prop="depart_name">
				<el-input v-model="form.depart_name" disabled clearable></el-input>
			</el-form-item><br>

			<el-form-item label="地区等级" prop="level">
				<el-select v-model="form.level" clearable>
					{if authCheck('users/becomevillage') }
					<el-option label="村级" value="1"></el-option>
					{/if}
					{if authCheck('users/becometown') }
					<el-option label="镇级" value="2"></el-option>
					{/if}
					{if authCheck('users/becomecounty') }
					<el-option label="县级" value="3"></el-option>
					{/if}
					{if authCheck('users/becomestate') }
					<el-option label="州级" value="4"></el-option>
					{/if}
				</el-select>
			</el-form-item>
			<el-form-item label="地址描点" prop="lnglat">
				<el-input v-model="form.lnglat" readonly clearable
					@focus="addMapoint">
				</el-input>
			</el-form-item><br>
			<el-form-item label="地址信息" prop="address">
				<el-input v-model="form.address" type="textarea" style="width:580px;"></el-input>
			</el-form-item><br>

			<el-form-item label="运营公司" prop="run_company">
				<el-input v-model="form.run_company" clearable></el-input>
			</el-form-item>
			<el-form-item label="运营地址" prop="run_address">
				<el-input v-model="form.run_address" clearable></el-input>
			</el-form-item><br>

			<el-form-item label="运营网址" prop="website">
				<el-input v-model="form.website" clearable></el-input>
			</el-form-item>
			<el-form-item label="电话" prop="linkType">
				<el-input v-model="form.linkType" clearable></el-input>
			</el-form-item><br>

			<el-form-item label="运营中心介绍" prop="remark">
				<textarea id="container"></textarea>
			</el-form-item><br>

			<el-form-item label=" ">
				<el-button plain type="primary" @click="subForm">提交</el-button>
			</el-form-item>
		</el-form>
	</div>
</el-card>
</el-col>
</el-row>
{/block}

{block name='script'}
<script src="__JS__/plugins/ueditor/ueditor.config.js"></script>
<script src="__JS__/plugins/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
var main = new Vue({
	el:"#main",
	data:{
		loading:false,
		optionGroup:'',
		goodsCateData:"",
		props:{
			label:"name",
		},
		form:{
			uid:"{$uid}",
			level:"",
			user_name:"{$user.user_name}",
			depart_name:"{$depart.name}",
			depart_id:"{$depart.id}",
			linkType:"",remark:"",
			lnglat:"",address:"",website:"",
			run_company:"",run_address:""
		},
		rules:{
			linkType:[{required:true,message:'请输入联系方式',trigger:['blur','change']}],
			website:[{required:true,message:'请输入QQ号',trigger:['blur','change']}],
			level:[{required:true,message:'请选择地区等级',trigger:['blur','change']}],
			lnglat:[{required:true,message:'请添加地址描点',trigger:['blur','change']}],
			address:[{required:true,message:'地址信息不能为空',trigger:['blur','change']}],
			run_company:[{required:true,message:'地址信息不能为空',trigger:['blur','change']}],
			run_address:[{required:true,message:'地址信息不能为空',trigger:['blur','change']}],
		}
	},
	mounted:function() {
		var opt = {
			initialFrameWidth:580,	// 设置默认宽度
			initialFrameHeight:200
		};
		this.editor = UE.getEditor('container',opt);
	},
	methods:{
		subForm() {
			this.form.remark = this.editor.getContent();
			this.$refs['form'].validate((valid) => {
				if (valid) {
					var param = this.form;
					$.post("./becomeCounty",param,function(res){
						if(res.code == 1){
							main.$notify({title:"错误",type:"success",message:res.msg})
						}else{
							main.$notify.error({title:"错误",message:res.msg})
						}
					})
				}
        	});
		},
		addMapoint() {
			$("#aMap").attr('src',"{:url('Gis/map_addpoint_tool')}?r=Math.random(0,9999)");
			map.showMap = true;
		}
	}
})
</script>
{/block}
